#ifndef AUDIODECODE_H
#define AUDIODECODE_H

#include <QThread>
#include "videoConfig.h"

#define MAX_AUDIO_FRAME_SIZE  1024
class audioDecode : public QThread
{
    Q_OBJECT
public:
    explicit audioDecode(QObject *parent);
    ~audioDecode();

    //音频输出初始化
    void Audio_Out_Init();
    void Audio_Out_Delete();
    /**
     * @brief           解码相关参数初始化
     * @author          wq
     * @time            2020-12-12
     * @param
     * @return
     * @remarks
     */
    void decodeParamInit();
    void decodeParamDelete();
    int threadStartUp();
    int threadStop();
protected:
    void run();
    ///////////////////////////////// 信号槽的定义 //////////////////////////////
public slots:

signals:


public://变量区

private:
    QAudioOutput *audio_out = Q_NULLPTR;
    QIODevice* audio_out_streamIn = Q_NULLPTR;
    QString video_file; //播放的视频文件
    struct audioDecodeParam
    {
        //音频转码后输出相关参数
        //采样的布局方式
        uint64_t out_channel_layout; //单声道音频布局
        //采样个数
        int out_nb_samples;
        //采样格式
        enum AVSampleFormat sample_fmt;
        //采样率
        int out_sample_rate;
        //通道数
        int out_channels;

        //音频解码相关的参数
        AVFrame *PCM_pFrame;
        //packet,用于存储解码前音频的数据
        AVPacket *packet;
        //创建buffer,存放转码后的数据
        int buffer_size;
        uint8_t *buffer;
        int64_t in_channel_layout;
        //转码参数
        struct SwrContext *convert_ctx;
        //一帧音频源数据,从上层队列中取
        AVPacket pkt;
        qint64 temp_audio_clock = 0; //音频时钟

        DecodingRelated *Decoding;
        PlayRelated* UIPlay;
    }audioDecodeParam;
};

#endif // AUDIODECODE_H
